package com.geek.framework.study.event.observer;

import com.geek.framework.study.event.EventListener;

import java.util.EventObject;
import java.util.Observable;
import java.util.Observer;

/**
 * @Author: ysq
 * @Date: 2021/9/1
 * @Description: 观察者适配器
 */
public class ListenerObserverAdapter implements Observer {

  private final EventListener listener;

  public ListenerObserverAdapter(EventListener listener) {
    this.listener = listener;
  }

  @Override
  public void update(Observable o, Object arg) {
    if (arg instanceof EventObject) {
      listener.onEvent((EventObject) arg);
    }
  }
}
